__file__ = 'A00.py'
__author__ = 'Jerry Liu'
__date__ = '2016-04-13'

"""
    问题：将你的 QQ 头像（或者微博头像）右上角加上红色的数字，类似于微信未读信息数量那种提示效果
    常用库：图像处理的库：PIL
        安装pillow库：
        1、http://www.lfd.uci.edu/~gohlke/pythonlibs/下载 Pillow-3.2.0-cp35-cp35m-win_amd64.whl
        2、使用命令pip install Pillow-3.2.0-cp35-cp35m-win_amd64.whl进行安装
"""

from PIL import Image, ImageFont, ImageDraw

def addtodo(path, num):
    # 新路径
    index = path.rfind('.')
    targetpath = path[:index]+'_num'+path[index:]
    # 读取图片
    try:
        img = Image.open(path)
        # 获取图片尺寸
        x, y = img.size
        # Windows :file:`fonts/` directory.
        myfont = ImageFont.truetype("verdanaz.ttf", 30)
        ImageDraw.Draw(img).text((2 * x / 3, 0), str(num), fill='red', font=myfont)
        img.save(targetpath)
    except FileNotFoundError:
        print('no file')

if __name__ == '__main__':
    addtodo('d://test.jpg', 4)
